package com.un.ebs.quality.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.quality.domain.QualityCheckExt;
import com.un.ebs.quality.dto.QualityCheckByInventoryDto;
import com.un.ebs.quality.dto.QualityCheckByProcessDto;
import com.un.ebs.quality.dto.QualityCheckPlanDto;
import com.un.ebs.quality.dto.QualityQueryDto;
import com.un.ebs.quality.enums.QualityTypeEnum;
import com.un.ebs.quality.service.QualityCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (QualityCheck)表控制层
 *
 * @author liubo
 * @since 2020-11-15 20:05:17
 */
@RestController
@RequestMapping("/qualityCheck")
@Api(value = "quality-check")
public class QualityCheckController {

    @Resource
    private QualityCheckService service;

    @GetMapping("queryCheckPlan")
    @ApiOperation(value = "查询，所有质检计划")
    public WebResult<List<QualityCheckPlanDto>> queryCheckPlan(@RequestParam(required = false) String searchText, @RequestParam(required = false) QualityTypeEnum type) {
        return WebUtils.success(service.queryCheckPlan(searchText, type));
    }

    @PostMapping("updateCheckPlanByProcess")
    @ApiOperation(value = "更新质检计划，过程检")
    public WebResult updateCheckPlanByProcess(@RequestParam String productionOrderId, @RequestParam Integer per) {
        service.updateCheckPlanByInventory(productionOrderId, per);
        return WebUtils.success();
    }

    @PostMapping("updateCheckPlanByInventory")
    @ApiOperation(value = "更新质检计划，出入库检")
    public WebResult updateCheckPlanByInventory(@RequestParam String inventoryNoteId, @RequestParam Integer per) {
        service.updateCheckPlanByInventory(inventoryNoteId, per);
        return WebUtils.success();
    }

    @PostMapping("checkByProcess")
    @ApiOperation(value = "生产过程质检")
    public WebResult checkByProcess(@RequestBody List<QualityCheckByProcessDto> req) {
        service.check(req);
        return WebUtils.success();
    }

    @PostMapping("checkPassByProcess")
    @ApiOperation(value = "生产过程质检，质检通过")
    public WebResult checkPassByProcess(@RequestParam String productionWorkOrderId) {
        service.checkPassByProduction(productionWorkOrderId);
        return WebUtils.success();
    }

    @PostMapping("checkPassByPurchase")
    @ApiOperation(value = "入库检，质检通过")
    public WebResult checkPassByPurchase(@RequestParam String inventoryItemId) {
        service.checkPassByPurchase(inventoryItemId);
        return WebUtils.success();
    }

    @PostMapping("checkByInventory")
    @ApiOperation(value = "出入库质检")
    public WebResult checkByInventory(@RequestBody QualityCheckByInventoryDto req) {
        service.check(req);
        return WebUtils.success();
    }

    @PostMapping("list")
    @ApiOperation(value = "查询")
    public WebResult<IPage<QualityCheckExt>> query(@RequestBody QualityQueryDto req) {
        return WebUtils.success(service.query(req.getSearchText(), req.getType(), req.getStartDate(), req.getEndDate(), req.getPageSize(), req.getPageIndex()));
    }
}